﻿using B.S.Passport.Domain;
using B.S.Passport.ErrorCode;
using B.S.Passport.Infacetrue;
using B.S.Passport.Read.API.Application.Command123;
using DAL;
using MediatR;

namespace B.S.Passport.Read.API.Application.Commandhander123
{
    public class GetWHouseModelCommandHander : IRequestHandler<GetWHouseModelCommand, ApiResult<List<WHouseModel>>>
    {
        public readonly IBaseRepository<WHouseModel> IWHouseModelrep;
        public readonly DBHelper1 dBHelper;

        public GetWHouseModelCommandHander(IBaseRepository<WHouseModel> IWHouseModelrep, DBHelper1 dBHelper)
        {
            this.IWHouseModelrep = IWHouseModelrep;
            this.dBHelper = dBHelper;
        }
        /// <summary>
        /// 获取仓库编号
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<WHouseModel>>> Handle(GetWHouseModelCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<WHouseModel>> apiResult = new ApiResult<List<WHouseModel>>();
            apiResult.Code = (ApiEnums)Renum.显示成功;
            apiResult.Message = Renum.显示成功.ToString();

            // 2. 正确查询数据库实体列表（假设WHouseType表对应实体是WHouseModel）
            var sql = "select * from WHouseModel";
            var houseModels = dBHelper.GetList<WHouseModel>(sql).ToList(); // 这里获取实体列表

            // 3. 将查询结果赋值给ApiResult的Data
            apiResult.Data = houseModels;

            return Task.FromResult(apiResult);
        }
    }
}
